<?php


namespace app\marketing\controller;
use app\ApiRest;
use app\marketing\model\PosterType as PosterTypeModel;


class IndexPosterType extends ApiRest
{
    public function listPosterType()
    {
        $param = $this->_param;
        //获取分页信息
        $page_config = array(
            'page' => 1,
            'page_count' => 20
        );
        //设置页码
        if (isset($param['page']) && $param['page'] > 0) $page_config['page'] = $param['page'];
        //设置每页的数据
        if (isset($param['page_count']) && $param['page_count'] > 0) $page_config['page_count'] = $param['page_count'];
        $filter[] = ['uniacid', '=', $this->_uniacid];

        $filter[] = ['status', '=', 1];

        if (isset($param['type_id']) && $param['type_id'] > 0) {
            $filter[] = ['type_id', '=', $param['type_id']];
        }

        $m_poster_type = new PosterTypeModel();
        $page_config['total'] = $m_poster_type->listPosterTypesCount($filter);
        $posters = $m_poster_type->listPosterTypes($filter, $page_config);
        $page_config['total_page'] = (int)($page_config['total'] / $page_config['page_count']);
        if (($page_config['total'] % $page_config['page_count']) > 0) $page_config['total_page'] = $page_config['total_page'] + 1;
        //设置返回参数
        $result = $page_config;
        //返回数据
        $result['data'] = $posters;
        return $this->success($result);


    }
}